Repository navigation
fix(loon): 兼容 WK3 主天气并修复空气质量与预警数据 - #107
hhhoratioxu wants to merge 8 commits into
Conversation
…bounded provider fallback
…esource boundaries
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dac6b02970
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!parameters.version || parameters.latitude === undefined || parameters.longitude === undefined || !Number.isFinite(latitude) || !Number.isFinite(longitude) || Math.abs(latitude) > 90 || Math.abs(longitude) > 180) return response; | ||
| let body; | ||
| try { body = JSON.parse(raw); } catch { return response; } | ||
| if (!object(body) || !productNames.some(name => object(body[name]) && object(body[name].metadata))) return response; |
There was a problem hiding this comment.
Adapt periodic-only v3 responses before returning
For a main-app v3 response containing only forecastPeriodic, this guard returns before normalization because productNames contains only the six replaceable products. The new rewrite in template/loon.handlebars still negotiates JSON for that request, so raw condition vectors and precipitation statistics reach the native reader instead of the required strings and scalars. The same periodic payload is normalized when an unrelated product such as currentWeather is also present. Include the known compatibility-only products in this acceptance check without making them provider-replacement targets.
Useful? React with 👍 / 👎.
| weatherAlerts.metadata = { ...weatherAlerts?.metadata, ...newWeatherAlerts.metadata }; | ||
| weatherAlerts.detailsUrl = newWeatherAlerts.detailsUrl ?? weatherAlerts.detailsUrl; | ||
| weatherAlerts.alerts = WeatherAlerts.mergeAlerts(weatherAlerts?.alerts, newWeatherAlerts?.alerts); | ||
| weatherAlerts.alerts = WeatherAlerts.mergeAlerts(weatherAlerts?.alerts, activeProviderAlerts(newWeatherAlerts?.alerts)); |
There was a problem hiding this comment.
Preserve unavailable alert status when no warnings are merged
When Apple supplies an unavailable weatherAlerts collection with alerts: [] and the selected provider returns active warnings, the provider's new temporarilyUnavailable: false overwrites Apple's flag here. However, WeatherAlerts.mergeAlerts returns the empty destination immediately when it has no rows (src/class/WeatherAlerts.mjs:102-104), so all fetched warnings are discarded and the output incorrectly reports an available empty collection. Preserve the unavailable state unless warnings are actually installed; the same transition needs guarding in the development processor.
Useful? React with 👍 / 👎.
- WeatherKit2/ForecastNextHour import the named WK2 namespace; shared constructors move to WK2.Common.ForecastMinute / WK2.Common.UUID. - WeatherKit3 gains a small FlatBufferRootProcessor subclass overriding only decode: a requested AQ child that fails to decode now yields null so the response keeps Apple's original package; a genuinely missing AQ still allows backfill. Encoding and other processor behavior is inherited. - Response.dev drops direct protocol imports, raw generated-table checks and enum-table selection; MatchEnum takes the business object and the request version and picks WK2/WK3 enum tables internally. - Port the shared PR #107/#108 fixes: epsilon-tolerant boundary ceiling in #CeilByPrecision, and idempotent QWeather CO unit handling in FixPollutantsUnits (explicit mg/m3 label, or the mislabeled Apple product only via appleProduct) with regression tests. - Tests migrate static/dynamic protocol imports to the three-namespace API.
- 拆分 WeatherKit 为 WeatherKit2/WeatherKit3 两个版本处理器,均基于 @nsnanocat/flatbuffer-root 配置通用根表编解码;WK3 仅注册 AQ 根槽, 其余产品保持原始 arena。 - WeatherKit3Processor 子类提供 decode 失败边界:已请求 AQ 读取或解码 失败时返回 null 保留原包,物理缺失允许补齐(基于包的 decodeWithReport 分类报告);checkFields 使用包的 inspectTable 做已验证字段数校验。 - 升级 @NSRingo/weatherkit 至 2.0.0(Common/WK2/WK3 命名空间)与 @nsnanocat/flatbuffer-root 至 ^1.1.0;共用构造器经 WK2.Common 引用。 - Response.dev 移除协议包直接导入、枚举表选择与原始生成表检查; MatchEnum 改为按请求版本内部选择枚举表。 - 移植 PR #107/#108 共同确认的修复:#CeilByPrecision 取整 EPSILON 容差、 FixPollutantsUnits 的 CO 单位幂等转换(appleProduct 入口)。 - WK3 与 WK2 的函数顺序、命名、参数排版对齐;两个 class 均补 JSDoc。 - 新增平台模拟回放测试(dist bundle、Surge 语义模拟)与 CO 单位回归。
- 拆分 WeatherKit 为 WeatherKit2/WeatherKit3 两个版本处理器,均基于 @nsnanocat/flatbuffer-root 配置通用根表编解码;WK3 仅注册 AQ 根槽, 其余产品保持原始 arena。 - WeatherKit3Processor 子类提供 decode 失败边界:已请求 AQ 读取或解码 失败时返回 null 保留原包,物理缺失允许补齐(基于包的 decodeWithReport 分类报告);checkFields 使用包的 inspectTable 做已验证字段数校验。 - 升级 @NSRingo/weatherkit 至 2.0.0(Common/WK2/WK3 命名空间)与 @nsnanocat/flatbuffer-root 至 ^1.1.0;共用构造器经 WK2.Common 引用。 - Response.dev 移除协议包直接导入、枚举表选择与原始生成表检查; MatchEnum 改为按请求版本内部选择枚举表。 - 移植 PR #107/#108 共同确认的修复:#CeilByPrecision 取整 EPSILON 容差、 FixPollutantsUnits 的 CO 单位幂等转换(appleProduct 入口)。 - WK3 与 WK2 的函数顺序、命名、参数排版对齐;两个 class 均补 JSDoc。 - 新增平台模拟回放测试(dist bundle、Surge 语义模拟)与 CO 单位回归。
- 拆分 WeatherKit 为 WeatherKit2/WeatherKit3 两个版本处理器,均基于 @nsnanocat/flatbuffer-root 配置通用根表编解码;WK3 仅注册 AQ 根槽, 其余产品保持原始 arena。 - WeatherKit3Processor 子类提供 decode 失败边界:已请求 AQ 读取或解码 失败时返回 null 保留原包,物理缺失允许补齐(基于包的 decodeWithReport 分类报告);checkFields 使用包的 inspectTable 做已验证字段数校验。 - 升级 @NSRingo/weatherkit 至 2.0.0(Common/WK2/WK3 命名空间)与 @nsnanocat/flatbuffer-root 至 ^1.1.0;共用构造器经 WK2.Common 引用。 - Response.dev 移除协议包直接导入、枚举表选择与原始生成表检查; MatchEnum 改为按请求版本内部选择枚举表。 - 移植 PR #107/#108 共同确认的修复:#CeilByPrecision 取整 EPSILON 容差、 FixPollutantsUnits 的 CO 单位幂等转换(appleProduct 入口)。 - WK3 与 WK2 的函数顺序、命名、参数排版对齐;两个 class 均补 JSDoc。 - 新增平台模拟回放测试(dist bundle、Surge 语义模拟)与 CO 单位回归。
- 拆分 WeatherKit 为 WeatherKit2/WeatherKit3 两个版本处理器,均基于 @nsnanocat/flatbuffer-root 配置通用根表编解码;WK3 仅注册 AQ 根槽, 其余产品保持原始 arena。 - WeatherKit3Processor 子类提供 decode 失败边界:已请求 AQ 读取或解码 失败时返回 null 保留原包,物理缺失允许补齐(基于包的 decodeWithReport 分类报告);checkFields 使用包的 inspectTable 做已验证字段数校验。 - 共用构造器经 WK2.Common 引用;Response.dev 移除协议包直接导入、 枚举表选择与原始生成表检查;MatchEnum 改为按请求版本内部选择枚举表。 - 移植 PR #107/#108 共同确认的修复:#CeilByPrecision 取整 EPSILON 容差、 FixPollutantsUnits 的 CO 单位幂等转换(appleProduct 入口)。 - WK3 与 WK2 的函数顺序、命名、参数排版对齐;两个 class 均补 JSDoc。 - 新增平台模拟回放测试(dist bundle、Surge 语义模拟)与 CO 单位回归。 - dev 模块模板的 weather 规则拆分为独立的 v2/v3 条目并修正命名。
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 355b5f5dad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await this.#RealTime("alerts"); | ||
| if (!Array.isArray(this.#cache.alert?.content)) throw Error(JSON.stringify(this.#cache.alert)); | ||
| weatherAlerts = { ...failedWeatherAlerts, ...this.#CreateWeatherAlerts(this.#cache.alert) }; |
There was a problem hiding this comment.
Consume the alert-specific response instead of shared cache state
When a Loon response fetches Caiyun current weather and alerts concurrently, the default TTLs allow a 30-second-old realtime response to satisfy the current-weather call while the alert call must refresh it. The current call repopulates #cache.alert, so if the alert refresh times out, #RealTime('alerts') returns {} but this code still converts the other call’s stale alerts and marks them available. This bypasses the 15-second alert TTL and failure fallback, allowing stale warnings to overwrite Apple warning fields. Consume alerts from the response returned by this specific call rather than the instance-wide cache slot.
Useful? React with 👍 / 👎.
Remove the nine optional cache, coalescing, request budget, cooldown, statistics, region fallback and alternate-provider controls. Keep original source settings, per-request timeouts and Apple failure fallback. Preserve unavailable Apple warnings unless enrichment changes actual data; retain opaque JSON containers and a normalized Apple fallback on overflow. Cover periodic and minute-rain edge cases and validate AQ comparison levels. Add source-native warning language preferences with Auto preserving old behavior. Normalize reserved expiry values without changing genuine times or manufacturing an event end. Preserve the original twelve defaults. Keep the PR's upstream release URLs, original display name, independent .loon.bundle.js files, package/lockfile policy and attribution. Retain all seven existing commits. Credit the referenced input-validation direction from Patrick Yan (NSRingo#108, 24c3f93) and known-container traversal from hhh2210 (NSRingo#110, f4676fe), as documented in the source. Validation: 430/430 regressions; 52 compiled Loon scenarios; 15 rewrite/jq checks; 13 declarations with all twelve original defaults preserved. Native evidence and remaining limits are documented separately.
🆕 New Features
.loon.bundle.js,其他客户端的原有模板与包版本策略保持不变。Auto / zh-Hans / en,默认 Auto 保持原行为。仅向当前所选来源请求其原生语言;来源不支持或返回原文/混合语言时,保留实际文字、签发单位和出处,不调用第三方翻译。显式偏好使用und消息语言标记及no-store详情响应,不改变主天气、空气质量等其他产品的语言。🛠️ Bug Fixes
forecastPeriodic/weatherChanges的回应仍适配已知字段,不发供应商请求;补齐 restOfDay、分钟降水末尾转折与空分钟表的边界。9999-12-31T00:00:00Z;真实来源及 Apple 时间保持原样,未知值不制造eventEndTime,真实已过期记录仍过滤。未将该旧边界归因为历史无正文的原因。配置与运行边界
验证与证据范围
0.0.0-test仅用于本 PR 既有构建夹具,原 package.json 与锁文件保持不变。.loon.bundle.js已重新完成真机安装验收。主天气、小时/每日预报、分钟雨、AQ/污染物和昨日对比的既有实机证据属于较早f571a49产物,本轮没有用新产物重新逐项实测,当前由回归与编译测试覆盖。英文完整原生 JSON、同一 HTTP 事务的 HTML/JSON 成对抓包、Surge 真机、其他地区/来源、原文回退的完整原生链路、iOS/watchOS、网络切换、长期 VPN 和资源量测仍未全面验证,不宣称本版全部功能或所有环境均通过实机验收。输入检查方向参考 Patrick Yan 的 #108(
24c3f931);已知容器遍历参考 hhh2210 的 #110(f4676fea,其 JSON 适配也注明源自 #107)。精确提交与 Apache-2.0 署名保留于源码。实现与边界:当前后续修复与验证、兼容说明、原版行为核对、较早原生观察记录。Refs #106。